#ifndef O_SYNC_STREAM_H
#define O_SYNC_STREAM_H
#include <fstream>
using namespace std;
#include <Locks.h>

class osyncstream : public ofstream
{
public:
	osyncstream()
	{
		_lock.Init();
	}
	~osyncstream()
	{
		_lock.Destroy();
	}
	bool open(const string& file = "")
	{
		if(file.empty())
		{
			basic_ios<char, char_traits<char> >::rdbuf(cout.rdbuf());
			return !ofstream::fail();
		}
		ofstream::open(file.c_str(), ios::app);
		return !ofstream::fail();
	}
	void lock()
	{
		_lock.Lock();
	}
	void unlock()
	{
		_lock.Unlock();
	}
private:
	SimpleLock	_lock;
};


#endif // !defined (O_SYNC_STREAM_H)

